from django.core.management.base import BaseCommand
from cinema.models import CinemaHall, Seat

class Command(BaseCommand):
    help = '为所有影厅初始化座位数据'

    def handle(self, *args, **options):
        halls = CinemaHall.objects.all()
        
        if not halls.exists():
            self.stdout.write(
                self.style.WARNING('没有找到影厅，请先创建影厅')
            )
            return
        
        total_seats_created = 0
        
        for hall in halls:
            # 检查是否已有座位
            existing_seats = Seat.objects.filter(hall=hall).count()
            if existing_seats > 0:
                self.stdout.write(
                    self.style.WARNING(f'影厅 {hall.name} 已有 {existing_seats} 个座位，跳过')
                )
                continue
            
            # 创建座位（10行10列）
            seats_created = 0
            for row in range(1, 11):
                for col in range(1, 11):
                    seat_number = f"{chr(64 + row)}{col:02d}"  # A01, A02, ..., J10
                    Seat.objects.create(
                        hall=hall,
                        row=chr(64 + row),
                        column=col,
                        seat_number=seat_number
                    )
                    seats_created += 1
            
            total_seats_created += seats_created
            self.stdout.write(
                self.style.SUCCESS(f'为影厅 {hall.name} 创建了 {seats_created} 个座位')
            )
        
        self.stdout.write(
            self.style.SUCCESS(f'总共创建了 {total_seats_created} 个座位')
        ) 